package com.example.wechar.service.message;

import com.example.wechar.pojo.TextMessage;
import com.example.wechar.service.IMessage;
import com.example.wechar.utils.WxCharConstant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;
@Service
public class TextMessageServiceImpl implements IMessage {
    @Value("${wx.appId}")
    String appId;

    //callBack修改成自己的
    @Value("${wx.callbackAddress}")
    String callBack;


    @Override
    public String handler(Map<String, Object> param) {
        String content ="校园安全平台,安心的校园,如果想体验更多功能,请回复[验证]";
        if(param.get(WxCharConstant.CONTENT).toString().equals("验证")){
            content = WxCharConstant.OAUTH2_AUTHORIZE.replace("APPID",appId)
                    .replace("REDIRECT_URI",callBack+"/wx/getCode")
                    .replace("SCOPE","snsapi_userinfo");
            System.out.println(content);
            content = "您好,请点击<a href='"+content+"'>登录</a>进行更多的操作";
        }
        TextMessage textMessage = TextMessage.ofSendMsg(param, content);
        return textMessage.toXml();
    }

}
